﻿Imports System.Collections.ObjectModel

Public Class ViewModelNewPMTWizardPageTblesFlux
    Inherits ViewModelNewPMTWizardPageBase


    Private _ObjTablesFlux As IPMTTablesflux
    Private _VMHistoCRT As ViewModelFichierPMT
    Private _VMHistoPMT As ViewModelFichierPMT
    Private _VMTxCom As ViewModelFichierPMT
    Private _VMDerCBP As ViewModelFichierPMT
    Private _VMReass As ViewModelFichierPMT

#Region "Constructeur"
    Public Sub New(PMT As IPMT)
        MyBase.New(PMT)
        _ObjTablesFlux = PMT.TablesPMTFlux
        _VMHistoCRT = New ViewModelFichierPMT(_ObjTablesFlux.HistoCRT, "Historique du CRT")
        AddHandler _VMHistoCRT.DirectoryExistsChanged, AddressOf OnDirectoryExistsChanged
        _VMHistoPMT = New ViewModelFichierPMT(_ObjTablesFlux.HistoPMT, "Historique du PMT")
        AddHandler _VMHistoPMT.DirectoryExistsChanged, AddressOf OnDirectoryExistsChanged
        _VMTxCom = New ViewModelFichierPMT(_ObjTablesFlux.TxComContractuels, "Taux de commissionnement contractuels")
        AddHandler _VMTxCom.DirectoryExistsChanged, AddressOf OnDirectoryExistsChanged
        _VMDerCBP = New ViewModelFichierPMT(_ObjTablesFlux.HistoCRT, "Déroulés CBP")
        AddHandler _VMDerCBP.DirectoryExistsChanged, AddressOf OnDirectoryExistsChanged
        _VMReass = New ViewModelFichierPMT(_ObjTablesFlux.HistoCRT, "Schéma de réassurance")
        AddHandler _VMReass.DirectoryExistsChanged, AddressOf OnDirectoryExistsChanged

        _ListViewModelsTablesFlux = New ObservableCollection(Of ViewModelFichierPMT)
        _ListViewModelsTablesFlux.Add(_VMHistoCRT)
        _ListViewModelsTablesFlux.Add(_VMHistoPMT)
        _ListViewModelsTablesFlux.Add(_VMTxCom)
        _ListViewModelsTablesFlux.Add(_VMDerCBP)
        _ListViewModelsTablesFlux.Add(_VMReass)
        _DisplayName = "Les tables du flux"

        'Observation des changements sur les fichiers PMT
        AddHandler _ObjTablesFlux.HistoCRT_Changed, AddressOf OnHistoCRT_Changed
        AddHandler _ObjTablesFlux.HistoPMT_Changed, AddressOf OnHistoPMT_Changed
        AddHandler _ObjTablesFlux.TxComContractuels_Changed, AddressOf OnTxCom_Changed
        AddHandler _ObjTablesFlux.DeroulesCBP_Changed, AddressOf OnDerCBP_Changed
        AddHandler _ObjTablesFlux.SchemaReass_Changed, AddressOf OnReass_Changed
    End Sub

    Public Sub New()
        MyBase.New(New PMT(New PMTParametresGeneraux, New PMTTablesflux))
        _ObjTablesFlux = PMT.TablesPMTFlux
        _ListViewModelsTablesFlux = New ObservableCollection(Of ViewModelFichierPMT)
        _ListViewModelsTablesFlux.Add(New ViewModelFichierPMT(_ObjTablesFlux.HistoCRT, "Historique du CRT"))
        _ListViewModelsTablesFlux.Add(New ViewModelFichierPMT(_ObjTablesFlux.HistoPMT, "Historique du PMT"))
        _ListViewModelsTablesFlux.Add(New ViewModelFichierPMT(_ObjTablesFlux.TxComContractuels, "Taux de commissionnement contractuels"))
        _ListViewModelsTablesFlux.Add(New ViewModelFichierPMT(_ObjTablesFlux.DeroulesCBP, "Déroulés CBP"))
        _ListViewModelsTablesFlux.Add(New ViewModelFichierPMT(_ObjTablesFlux.SchemaReass, "Schéma de réassurance"))
        _DisplayName = "Les tables du flux"
    End Sub
#End Region

#Region "Propriétés"
    Private _ListViewModelsTablesFlux As ObservableCollection(Of ViewModelFichierPMT)
    Public ReadOnly Property ListViewModelsTablesFlux As ObservableCollection(Of ViewModelFichierPMT)
        Get
            Return _ListViewModelsTablesFlux
        End Get
    End Property

    Private _DisplayName As String
    Public Overrides ReadOnly Property DisplayName As String
        Get
            Return _DisplayName
        End Get
    End Property

    'Renvoie vrai si l'étape est validée
    Public Overrides ReadOnly Property IsValid() As Boolean
        Get
            Return (_VMHistoCRT.Exists And _VMHistoPMT.Exists And _VMDerCBP.Exists And _VMTxCom.Exists And _VMReass.Exists)
        End Get
    End Property
#End Region

#Region "Méthodes"
    Private Sub OnHistoCRT_Changed(sender As Object, e As EventArgs)
        _VMHistoCRT.FichierPMT = _ObjTablesFlux.HistoCRT
        OnPropertyChanged("ListViewModelsTablesFlux")
    End Sub
    Private Sub OnHistoPMT_Changed(sender As Object, e As EventArgs)
        _VMHistoPMT.FichierPMT = _ObjTablesFlux.HistoPMT
    End Sub
    Private Sub OnTxCom_Changed(sender As Object, e As EventArgs)
        _VMTxCom.FichierPMT = _ObjTablesFlux.TxComContractuels
    End Sub
    Private Sub OnDerCBP_Changed(sender As Object, e As EventArgs)
        _VMDerCBP.FichierPMT = _ObjTablesFlux.DeroulesCBP
    End Sub
    Private Sub OnReass_Changed(sender As Object, e As EventArgs)
        _VMReass.FichierPMT = _ObjTablesFlux.SchemaReass
    End Sub

    Private Sub OnDirectoryExistsChanged(sender As Object, e As EventArgs)
        OnPropertyChanged("IsValid")
    End Sub
#End Region

End Class
